<?php
$idobjetivo = $this->user = sfContext::getInstance()->getUser()->getAttribute('id_obs');
$q = Doctrine_Query::create()
        ->from('objetivo o')
        ->where('o.id_ob=?', $idobjetivo);
$objetivoseleccionado = $q->fetchOne();
$fi = explode("-", $objetivoseleccionado->getPeriodos()->getFechai());
$ff = explode("-", $objetivoseleccionado->getPeriodos()->getFechaf());
$ai = $fi[0];
$mi = $fi[1];
$af = $ff[0];
$mf = $ff[1];




//datos de entrada
$ainicial = $ai;
$afinal = $af;

$minicial = $mi;
$mfinal = $mf;
//
$a = 0;
$aux = $ainicial;
$cainter = 0;
$cpas = 0;
$aunico = 0;
$meses = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre", "no existe");
$imes = 0;
$medmes = 0;
$fmes = 0;
$tomes = 0;
$cmes = 0;
?>
<tr style="border-color:#00000;">
    <td colspan="2" id="filascolor" align="center">LISTA</td>
    <?php if ($ainicial == $afinal) { ?>
        <td align="center" colspan="<?php echo ((($mfinal - $minicial) + 1)); ?>"><?php echo $ainicial; ?></td>
    <?php } else { ?>
        <td align="center" id="filascolor3" colspan="<?php echo (((12 - $minicial) + 1)); ?>"><?php echo $ainicial; ?></td>
        <?php
        if ($aux + 1 != $afinal) {
            while (($aux + 1 > $ainicial) && ($aux + 1 < $afinal)) {
                ?>
              <?php $res=($aux+1)%2;?>
               <?php if($res==0){?>
                <td align="center" colspan="<?php echo(12);?>"><?php echo $aux + 1; ?></td>
               <?php }else{?>
                <td align="center" id="filascolor2" colspan="<?php echo(12);?>"><?php echo $aux + 1; ?></td>
              <?php }?>  
                <?php $aux++; ?>
            <?php }
        } ?>
        <td align="center" id="filascolor3" colspan="<?php echo $mfinal; ?>"><?php echo $afinal; ?></td>
    <?php } $aux = $ainicial; ?>
    <td rowspan="2" align="center">SUBTOTAL:</td>
</tr>
<tr style="border-color:#00000;" id="filascolor">
    <td align="center">CODIGO</td>
    <td align="center">DETALLE</td>
    <?php if ($ainicial == $afinal) {
        if ($minicial == $mfinal) { ?>
            <td align="center"> NO PUEDE EXISTIR UN PROYECTO DE 1 MES</td>
            <?php $cmes = 1; ?>
        <?php } else { ?>
            <?php for ($mc = $minicial; $mc <= $mfinal; $mc++) { ?>
                <td align="center"><?php echo $meses[$mc - 1]; ?></td>
                <?php $cmes++; ?>
                <?php
            } $tomes = $cmes;
        }
    } else {
        ?>
        <?php for ($mc = $minicial; $mc <= 12; $mc++) { ?>
            <td align="center"><?php echo $meses[$mc - 1]; ?></td>
            <?php $imes++; ?>
        <?php }$mc = 13;
        $imes; ?>
        <?php if ($aux + 1 == $afinal) { ?>
            <?php if ($mc == 13) {
                for ($mc = 1; $mc <= $mfinal; $mc++) { ?>
                    <td align="center"><?php echo $meses[$mc - 1]; ?></td>
                    <?php $fmes++;
                } ?>
            <?php }$tomes = $fmes + $imes; ?>
        <?php } else {
            while ($aux + 1 != $afinal) { ?>
                <?php if ($mc == 13) { ?>
                    <?php for ($mc = 1; $mc <= 12; $mc++) { ?>
                        <td align="center"><?php echo $meses[$mc - 1]; ?></td>
                        <?php
                        $medmes++;
                    }
                }
                ?>
                <?php $aux++;
                $mc = 13; ?>
            <?php } $medmes; ?>
            <?php
        }
        if ($mc == 13) {
            for ($mc = 1; $mc <= $mfinal; $mc++) {
                ?>
                <td align="center"><?php echo $meses[$mc - 1]; ?></td>
                <?php
                $fmes++;
            }
        } $fmes;
        ?>
    <?php }$tomes = $imes + $medmes + $fmes; ?>
    <?php return $tomes; ?>
</tr>

